﻿@model Bricks.Site.Models.CircularView

@{
    ViewBag.Title = "检查通报";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        initTable();
    });
    function initTable(queryData) {
        $('#circularDataGrid').datagrid({
            url: '/Circular/GetDataList',
            //iconCls: 'icon-bricks',
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            pagination: true,
            pageSize: 20,
            rownumbers: true,
            //sortName: 'ID',    //根据某个字段给easyUI排序
            //sortOrder: 'asc',
            remoteSort: false,
            idField: 'ID',
            checkOnSelect: true,
            selectOnCheck: true,
            singleSelect: true,
            queryParams: queryData,  //异步查询的参数
            toolbar: '#circularToolBar',
            columns: [[
                { title: '@Html.LabelFor(model => model.CircularName)', field: 'CircularName', width: 300, sortable: true },
                { title: '@Html.LabelFor(model => model.PublishTime)', field: 'PublishTime', width: 140, sortable: true, formatter: function (value, rec) { if (value) { return dateConvert(value); } } },  //此处进行时间格式转换
                //{ title: '@Html.LabelFor(model => model.PublishTime)', field: 'PublishTime', width: 100, sortable: true },
                { title: '@Html.LabelFor(model => model.PublishOrg)', field: 'PublishOrg', width: 150, sortable: true },
                { title: '@Html.LabelFor(model => model.PublishUser)', field: 'PublishUser', width: 100, sortable: true },
                {
                    title: '@Html.LabelFor(model => model.IsCorrective)', field: 'IsCorrective', width: 60, sortable: true, align: "center",
                    formatter: function (value, row, index) {
                        return $.GetYesOrNo(value);  //是否禁用图标（是/否）
                    }
                }
            ]],
            //非发布人禁用修改和删除按钮
            onClickRow: function (rowIndex, rowData) {
                if (rowData.PublishUserID != rowData.LoginUserID) {
                    $('#btnModify').linkbutton('disable');
                    $('#btnDelete').linkbutton('disable');
                }
                else {
                    $('#btnModify').linkbutton('enable');
                    $('#btnDelete').linkbutton('enable');
                }
            },
            //双击弹出预览
            onDblClickRow: function (rowIndex, rowData) {
                Circular.Preview();
            }
        });
    }
    var Circular = {
        //新增
        Add: function () {
            //debugger;
            Circular.Mutual("新增", "/Circular/Edit", true);
        },

        //修改
        Modify: function () {
            var row = $("#circularDataGrid").datagrid("getSelected");
            if (row) {
                Circular.Mutual("修改", "/Circular/Edit?ID=" + row.ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        Mutual: function (title, href, isAdd) {
            $.ModelDialog({
                title: title, href: href, width: 600,
                handler: function () {
                    $.ModelForm({
                        validate: true, button: $(this),
                        id: "#circular-model",
                        url: "/Circular/EditPost",
                        success: function (result) { Circular.Reload(); }
                    });
                },
                onLoad: function () { Circular.FormInit(isAdd); }
            });
        },

        //弹窗初始化
        FormInit: function (isAdd) {
            //$("#isCorrective").combobox({
            //    editable: false, width: 155, panelHeight: "auto",
            //    data: [
            //        { value: 1, text: "是" },
            //        { value: 0, text: "否" }]
            //});

            //发布单位（下拉）--因为一个用户可能属于多个单位
            $("#publishOrgID").combobox({
                url: "/Account/GetUserOrgsByUserID?userID=" + $("#hPublishUserID").val(),
                editable: false, width: 155, panelHeight: "auto",
                valueField: "ID",
                textField: "OrgName",
                //如果是新增，则让下拉框默认选中第一个
                onLoadSuccess: function () {
                    if (isAdd) {
                        var data = $("#publishOrgID").combobox('getData');
                        if (data.length > 0) {
                            $("#publishOrgID").combobox('select', data[0]["ID"]);
                        }
                    }
                }
            });
        },

        //预览
        Preview: function () {
            var row = $("#circularDataGrid").datagrid("getSelections");
            if (row.length == 1) {
                Circular.PreviewMutual("预览", "/Circular/Preview?id=" + row[0].ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        PreviewMutual: function (title, href) {
            $.ModelDialog({
                title: title, href: href, maximized: true
            });
        },

        //详细
        Detail: function () {
            var row = $("#circularDataGrid").datagrid("getSelections");
            if (row.length == 1) {
                Circular.DetailMutual("详细", "/Circular/Detail?id=" + row[0].ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //详细实体操作
        DetailMutual: function (title, href) {
            $.ModelDialog({
                title: title, href: href, width: 600,
                onLoad: function () { Circular.FormInit(true); }
            });
        },

        //删除
        Delete: function () {
            var arr = $('#circularDataGrid').datagrid('getSelections');

            if (arr.length == 1) {
                $.messager.confirm('操作提示', "确认删除[ " + arr[0].CircularName + " ]吗？", function (r) {
                    if (r) {
                        $.post("/Circular/Delete?ID=" + arr[0].ID, { query: arr.join(",") }, function (result) {
                            if (result.ResultType == 0) {  //0表示成功
                                //移除删除的数据
                                //$("#myTreeGrid").datagrid("reload");
                                //$("#myTreeGrid").datagrid("clearSelections");
                                //$.messager.alert('操作提示', '删除成功!', 'info');
                                $.EasyuiSlide(result.Message);
                                Circular.Reload();
                            }
                            else {
                                $.EasyuiMsg(result.Message);
                            }
                        });
                    }
                });

            } else {
                //$.messager.alert('操作提示', '请选择一条数据!', 'warning');
                $.EasyuiMsg("请选择一条数据");
            }
            return false;
        },

        //刷新
        Reload: function () {
            $("#circularDataGrid").datagrid("reload");
        }
    }
</script>

<table id="circularDataGrid" fit="true"></table>
@*<div id="circularToolBar">
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='Circular.Add()' data-options='plain:true,iconCls:"icon-application_add"'>新增</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='Circular.Modify()' data-options='plain:true,iconCls:"icon-application_delete"'>修改</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='Circular.Delete()' data-options='plain:true,iconCls:"icon-bell"'>删除</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='Circular.Reload()' data-options='plain:true,iconCls:"icon-blue_lego"'>刷新</a>
    </div>*@
<div id="circularToolBar">@Html.Raw(ViewBag.ToolBarInfo)</div>
